package com.mjee.service;

import java.util.List;

import com.mjee.dao.UserDao;
import com.mjee.entity.User;
import com.mtoolkit.page.Page;
import com.mtoolkit.util.DateUtil;

public class UserServiceImpl implements UserService {

	private UserDao userDao;
	
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
	@Override
	public void addUser(User user) {
		if (user == null) {
			throw new NullPointerException("user");
		}
		if (user.getUserName() == null || user.getPassword() == null) {
			throw new IllegalArgumentException();
		}
		
		user.setRegisterTime(DateUtil.getCurrentDate());
		userDao.insertUser(user);
	}

	@Override
	public User findUser(String userName, String password) {
		return userDao.selectUser(userName, password);
	}

	@Override
	public List<User> queryUsers(Page page) {
		if (page == null) {
			page = new Page(1, 10);
		}
		
		return userDao.selectUsers(page);
	}

}
